package physicalobject;

import java.awt.geom.Point2D;

public class Bar extends Connector {

    /**
     * Constructor for spring.
     * @param start the mass on one end of the spring
     * @param end the mass on the other end of the spring
     * @param length the rest length of the spring
     * @param kVal the "springiness" of the spring
     */
    public Bar (final Mass start, final Mass end, final double length,
            final double kVal) {
        super(start, end, length, kVal);
        setK();
    }

    /**
     * Set a K value proportional to the distance between the two masses
     * and resting length.
     * only for bars (when K > 0)
     */
    private void setK () {
        Point2D startPT = myStart.getCenter();
        Point2D endPT = myEnd.getCenter();
        double distance = Math.sqrt((startPT.getX() - endPT.getX())
                 * (startPT.getX() - endPT.getX())
                 + (startPT.getY() - endPT.getY())
                 * (startPT.getY() - endPT.getY()));
        myK = Math.abs(distance - myLength) * MIN_LENGTH;
     //    System.out.println(myStart + "  " + myK);
    }

    @Override
    public double getLength (double timeElapsed) {
        return myLength;
    }
}
